package com.sltx.controller;

import com.sltx.controller.base.BaseController;
import com.sltx.service.YzqyService;
import com.sltx.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 创新企业
 */
@Controller
@RequestMapping(value = "/yzqy")
public class YzqyController extends BaseController {
    @Autowired
    private YzqyService yzqyService;


    //创新(优质)企业
    @RequestMapping("/getYzqyList")
    @ResponseBody
    public Object getYzqyList(HttpServletRequest request){
       Map<String,Object> result = new HashMap<String, Object>();
        PageData pd = this.getPageData();
        int pageSize = Integer.parseInt(pd.get("pageSize").toString());
        int pageNo = Integer.parseInt(pd.get("pageNo").toString());
        Integer startPage = ((pageSize*(pageNo-1)));
        pd.put("startPage",startPage.toString());
        //获取最大季度
        String bigqua = yzqyService.bigQuarter();
        pd.put("bigqua",bigqua);
        //获取查询的年份和季度
        Map<String,Object> Yearandquarterlt = yzqyService.getYearandquarterlt(pd);
        //获取条数
        result.put("num",yzqyService.getNum(pd));
        //获取最新季度数据
        List<Map<String, Object>> list = yzqyService.getYzqyList(pd);
        for (Map<String, Object> map : list) {
            String composite_scores = map.get("composite_scores").toString();
            map.put("composite_scores",composite_scores);
        }
        result.put("Yearandquarterlt",Yearandquarterlt);
        result.put("list",list);


        return result;
    }
    /*
     *企业关键字查询
     * */
    @RequestMapping("/getCxqyByName")
    @ResponseBody
    public Object getCxqyByName(HttpServletRequest request){
        Map<String,Object> result = new HashMap<String, Object>();
        PageData pd = this.getPageData();

        int pageSize = Integer.parseInt(pd.get("pageSize").toString());
        int pageNo = Integer.parseInt(pd.get("pageNo").toString());

        Integer startPage = ((pageSize*(pageNo-1)));
        Integer endPage = startPage+pageSize;

        pd.put("startPage",startPage.toString());
        pd.put("endPage",endPage.toString());

        if ("年份".equals(pd.get("update_year"))){
            pd.remove("update_year");
        }
        if ("季度".equals(pd.get("update_year"))){
            pd.remove("update_year");
            pd.put("update_quarterly","季度");
        }

        result.put("num",yzqyService.getCxqyByNameNum(pd));
        result.put("list",yzqyService.getCxqyByName(pd));

        return result;
    }
}
